package org.cybergarage.http;

import org.cybergarage.net.HostInterface;

public class SecureHTTPServerList extends HTTPServerList {

	public SecureHTTPServerList()
	{
		
	}
	
	public SecureHTTPServer getHTTPServer(int n)
	{
		return (SecureHTTPServer)get(n);
	}
	
	public void close()
	{
		int nServers = size();
		for(int n=0; n<nServers; n++){
			SecureHTTPServer server = getHTTPServer(n);
			server.close();
		}
	}
	
	public boolean open(int port)
	{
		int nHostAddrs = HostInterface.getNHostAddresses();
		for (int n=0; n<nHostAddrs; n++) {
			String bindAddr = HostInterface.getHostAddress(n);
			SecureHTTPServer secureHTTPServer = new SecureHTTPServer();
			if (secureHTTPServer.open(bindAddr, port) == false) {
				close();
				clear();
				return false;
			}
			add(secureHTTPServer);
		}
		return true;
	}
	
	public void start()
	{
		int nServers = size();
		for(int n=0; n<nServers; n++){
			SecureHTTPServer server = getHTTPServer(n);
			server.start();
		}
	}
	
	public void stop()
	{
		int nServers = size();
		for(int n=0; n<nServers; n++){
			SecureHTTPServer server = getHTTPServer(n);
			server.stop();
		}
	}
}
